package com.probiz.estore.attribute.dao.impl;

import java.util.List;

import com.probiz.estore.attribute.dao.AttributeDao;
import com.probiz.estore.common.model.attribute.Attribute;
import com.probiz.estore.core.dao.impl.HibernateGenericDaoImpl;

/**
 * Dao implementation for Attribute.
*/
public class AttributeDaoImpl extends HibernateGenericDaoImpl<Attribute> implements AttributeDao {
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.attribute.dao.AttributeDao#getAttributeByCode(java.lang.String)
	 */
	public Attribute getAttributeByCode(String attributeCode){
		String hql = "from Attribute a where a.attributeCode=?";
		Object ob = super.findUnique(hql, attributeCode);
		return (Attribute)ob;
	}
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.attribute.dao.AttributeDao#getAttributes(java.lang.Short)
	 */
	public List<Attribute> getAttributes(Short attributeType) {
		String hql = "from Attribute a where a.attributeType=?  order by a.sortOrder asc";
		List<Attribute> list = super.findByHql(hql, attributeType);
		return list;
	}
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.attribute.dao.AttributeDao#getActiveAttributes(java.lang.Short)
	 */
	public List<Attribute> getActiveAttributes(Short attributeType){
		String hql = "from Attribute a where a.attributeType=? and a.status=1 order by a.sortOrder asc";
		List<Attribute> list = super.findByHql(hql, attributeType);
		return list;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.attribute.dao.AttributeDao#getInvalidProductAttributes()
	 */
	public List<Attribute> getInvalidProductAttributes(){
		return (List<Attribute>)this.findByHql("from Attribute a where a.attributeType = 1 and a.attributeId not in (select i.attribute.attributeId from ProductAttGroupItem i)");
	}

	
}
